
new Vue({
    el: '#app',
    delimiters:['[[', ']]'],

    data: {
        gifts: [],
        categories: [],
    },

    methods: {
        /**
         * 请求礼物分类列表
         */
        requestGiftCategoryList() {
            let url = "{% url 'gma:api_get_gift_category_list' %}";
            new my_ajax(url, {}, '', '', (data) => {
                console.table(data);
                this.categories = data;
            });
        },

        /**
         * 请求礼物列表
         */
        requestGiftList() {
            let url = "{% url 'gma:api_get_gift_list' %}";
            new my_ajax(url, {}, '', '', (data) => {
                console.table(data);
                this.gifts = data;

                this.gifts.forEach(gift => {
                    if (gift.resource.toLowerCase().endsWith('.svga')) {
                        gift.resource_url = `/gma/gallery/${gift.resource}/`;
                    } else {
                        gift.resource_url = gift.resource;
                    }
                });
            });
        },
    },

    mounted() {
        this.requestGiftList();
        this.requestGiftCategoryList();
    },
});
